package org.csu.mypetstore.service;


import org.apache.ibatis.annotations.Param;
import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.domain.Cart;
import org.csu.mypetstore.domain.CartItem;
import org.csu.mypetstore.persistence.CartMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@MapperScan
@EnableAutoConfiguration

public class CartService {

    @Autowired
    private CartMapper cartMapper;

    public List<Cart> getCartItemsByUsername(Account account){
        return cartMapper.getCartItemsByUsername(account);
    }

    public void updateCartItemQty(String username,String qty,String id){
        cartMapper.updateCartItemQty(username,qty,id);
    }


    public void addCartItem(String username,String id){
        cartMapper.addCartItem(username,id);
    }

    public void submitItem(Account account){
        cartMapper.submitItem(account);
    }

    public void updateInventory(List<Cart> carts){
        cartMapper.updateInventory(carts);
    }

    //根据用户信息获取购物车
    public List<CartItem> getCartItemList(String userid){
        return cartMapper.getCartItemList(userid);

    }

    public void insertCartItem(@Param("itemId")String itemId, @Param("userid")String userid, @Param("quantity")int quantity){
        cartMapper.insertCartItem(itemId,userid,quantity);
    }

    public void updateCartItem(@Param("itemId")String itemId, @Param("userid")String userid, @Param("quantity")int quantity){
        cartMapper.updateCartItem(itemId,userid,quantity);
    }


    public void removeCartItem(String username,String id){
        cartMapper.removeCartItem(username,id);
    }

}